import request from '@/utils/request';

// 获取目录树结构
export const getCatalogTree = (categoryId) => {
  return request({
    url: `/catalog/tree/${categoryId}`,
    method: 'get'
  });
};

// 添加目录节点
export const addCatalogNode = (data, parentId = null) => {
  return request({
    url: '/catalog',
    method: 'post',
    data: {
      ...data,
      parentId,
      categoryId: data.categoryId
    }
  });
};

// 更新目录节点
export const updateCatalogNode = (data) => {
  return request({
    url: `/catalog`,
    method: 'put',
    data
  });
};

// 删除目录节点
export const deleteCatalogNode = (nodeId) => {
  return request({
    url: `/catalog/${nodeId}`,
    method: 'delete'
  });
};

// 根据内容代码和分类ID查询文章内容
export const getArticleByContentCode = (code, categoryId) => {
  return request({
    url: `/article/content/code/${code}/category/${categoryId}`,
    method: 'get'
  });
};

// 创建目录
export const createCatalogContent = (data) => {
  return request({
    url: '/article/content/create',
    method: 'post',
    data
  });
};

// 根据ID更新目录内容
export const updateCatalogContent = (id, data) => {
  return request({
    url: `/article/content/update/${id}`,
    method: 'put',
    data
  });
};

// 根据ID获取文章内容详情
export const getCatalogContentById = (id) => {
  return request({
    url: `/article/content/${id}`,
    method: 'get'
  });
};

export const deleteArticleContent = (id) => {
  return request({
    url: `/article/content/${id}`,
    method: 'delete'
  });
};

